package com.woniuxy.dr_mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.dr_mall.entity.DrCommentInfo;
import com.woniuxy.dr_mall.entity.DrComment;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 张哲轩
 * @since 2021-08-11
 */
public interface DrCommentMapper extends BaseMapper<DrComment> {
    @Select("select oi.id orderItemId,o.orderNo orderNo,o.orderTime orderTime,o.accept accept,o.telephone telephone,o.money money,p.name name,p.id productsId\n" +
            "from dr_orders o,\n" +
            "     dr_orders_item oi,\n" +
            "     dr_products p,\n" +
            "     dr_spec_price sp\n" +
            "where o.userId = #{userId} and oi.status = 'n'\n" +
            "  and o.id = oi.ordersId\n" +
            "  and oi.skuId = sp.id\n" +
            "  and sp.productId = p.id")
    List<DrCommentInfo> getNotComment(@Param("userId")Integer userId);

    @Select("select count(*)\n" +
            "from dr_orders o,\n" +
            "     dr_orders_item oi,\n" +
            "     dr_products p,\n" +
            "     dr_spec_price sp\n" +
            "where o.userId = #{userId} and oi.status = 'n'\n" +
            "  and o.id = oi.ordersId\n" +
            "  and oi.skuId = sp.id\n" +
            "  and sp.productId = p.id")
    int getNotCommentCount(@Param("userId")Integer userId);

    @Select("select *\n" +
            "from\n" +
            "dr_comment c\n" +
            "where userId = #{userId}\n")
    List<DrComment> getCommentByUserId(@Param("userId")Integer userId);

    @Delete("delete from dr_comment where id = #{id}")
    void delById(Integer id);

    @Insert("insert into dr_comment(userId,ProductId,text,time,rate,status,orderItemId) values(#{userId},#{ProductId},#{text},#{time},#{rate},#{status},#{orderItemId})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void add(DrComment drComment);

    @Select("select * from dr_comment where ProductId = #{ProductId}")
    List<DrComment> getProductCommentByPId(@Param("ProductId") int ProductId);

}
